<cfcomponent output="false" displayname="user" hint="I am a user.">

	<cfset variables.instance = structNew()>
	<cfset variables.instance.id = 0>
	<cfset variables.instance.firstname = "">
	<cfset variables.instance.lastname = "">
	<cfset variables.instance.email = "">
	<cfset variables.instance.middlename = "">
	<cfset variables.instance.addresses = "">

	<cffunction name="init" access="public" returntype="any" output="no">
		<cfargument name="id" required="no" type="numeric" default="0">
		<cfargument name="firstname" required="no" type="string" default="">
		<cfargument name="lastname" required="no" type="string" default="">
		<cfargument name="email" required="no" type="string" default="">
		<cfargument name="middlename" required="no" type="string" default="">
		<cfargument name="addresses" required="no" type="array" default="#arrayNew(1)#">
		<cfset setInstanceMemento(arguments)>
		<cfreturn this />
	</cffunction>

	<cffunction name="getID" access="public" output="no" returntype="numeric">
		<cfreturn variables.instance.id>
	</cffunction>
	<cffunction name="setID" access="public" output="no" returntype="void">
		<cfargument name="id" required="yes" type="numeric">
		<cfset variables.instance.id = arguments.id>
	</cffunction>
	<cffunction name="getFirstname" access="public" output="no" returntype="string">
		<cfreturn variables.instance.firstname>
	</cffunction>
	<cffunction name="setFirstname" access="public" output="no" returntype="void">
		<cfargument name="firstname" required="yes" type="string">
		<cfset variables.instance.firstname = arguments.firstname>
	</cffunction>
	<cffunction name="getLastname" access="public" output="no" returntype="string">
		<cfreturn variables.instance.lastname>
	</cffunction>
	<cffunction name="setLastname" access="public" output="no" returntype="void">
		<cfargument name="lastname" required="yes" type="string">
		<cfset variables.instance.lastname = arguments.lastname>
	</cffunction>
	<cffunction name="getEmail" access="public" output="no" returntype="string">
		<cfreturn variables.instance.email>
	</cffunction>
	<cffunction name="setEmail" access="public" output="no" returntype="void">
		<cfargument name="email" required="yes" type="string">
		<cfset variables.instance.email = arguments.email>
	</cffunction>
	<cffunction name="getMiddlename" access="public" output="no" returntype="string">
		<cfreturn variables.instance.middlename>
	</cffunction>
	<cffunction name="setMiddlename" access="public" output="no" returntype="void">
		<cfargument name="middlename" required="yes" type="string">
		<cfset variables.instance.middlename = arguments.middlename>
	</cffunction>
	<cffunction name="getAddresses" access="public" output="no" returntype="array">
		<cfreturn variables.instance.addresses>
	</cffunction>
	<cffunction name="setAddresses" access="public" output="no" returntype="void">
		<cfargument name="addresses" required="yes" type="array">
		<cfset variables.instance.addresses = arguments.addresses>
	</cffunction>
	<cffunction name="addAddress" access="public" output="no" returntype="void">
		<cfargument name="address" required="yes" type="cfhibernate.model.user.address.address">
		<cfset arrayAppend(variables.instance.addresses, arguments.address)>
	</cffunction>
	<cffunction name="getInstanceMemento" access="public" returntype="struct" output="false">
		<cfset var data = structNew()>
		<cfset var addresses = getAddresses()>
		<cfset data.id = getID()>
		<cfset data.firstName = getFirstname()>
		<cfset data.lastName = getLastname()>
		<cfset data.email = getEmail()>
		<cfset data.middleName = getMiddlename()>
		<cfset data.addresses = arrayNew(1)>
		<cfloop from="1" to="#arrayLen(addresses)#" index="i">
			<cfset arrayAppend(data.addresses, addresses[i].getInstanceMemento())>
		</cfloop>
		<cfreturn data>
	</cffunction>
	<cffunction name="getTO" access="public" returntype="struct" output="false">
		<cfset var data = structNew()>
		<cfset var addresses = getAddresses()>
		<cfset data["id"] = getID()>
		<cfset data["firstName"] = getFirstname()>
		<cfset data["lastName"] = getLastname()>
		<cfset data["email"] = getEmail()>
		<cfset data["middleName"] = getMiddlename()>
		<cfset data["addresses"] = arrayNew(1)>
		<cfloop from="1" to="#arrayLen(addresses)#" index="i">
			<cfset arrayAppend(data.addresses, addresses[i])>
		</cfloop>
		<cfreturn data>
	</cffunction>
	<cffunction name="setInstanceMemento" access="public" returntype="void" output="false">
		<cfargument name="data" type="struct" required="true">
		<cfset setID(arguments.data.id)>
		<cfset setFirstname(arguments.data.firstname)>
		<cfset setLastname(arguments.data.lastname)>
		<cfset setEmail(arguments.data.email)>
		<cfset setMiddlename(arguments.data.middlename)>
		<cfset setAddresses(arguments.data.addresses)>
	</cffunction>

</cfcomponent>